package model;

import java.sql.*;
import java.util.Date;
import dal.*;

public class VenueModel implements IModel {

	public class ErrorMessages {
		public String Id = "";
		public String Name = "";
		public String Code = "";
		public String Description = "";
		public String IdCompany = "";
		public String AbbName = "";
		public String ShortName = "";
		public String ForeignName = "";
		public String Address = "";
		public String Mobile = "";
		public String Capacity = "";
		public String Status = "";
		public String IsDraft = "";
		public String Notification = "";
		public String Created = "";
		public String Creator = "";
		public String Updated = "";
		public String Updator = "";
		public String Deleted = "";
		public String DeletionTime = "";
	
	}

    public ErrorMessages errMsgs = new ErrorMessages();

	public String[] errMsgList = null;

// private variables
private int _id = Integer.MIN_VALUE;
private String _name = null;
private String _code = null;
private String _description = null;
private int _id_company = Integer.MIN_VALUE;
private String _abb_name = null;
private String _short_name = null;
private String _foreign_name = null;
private String _address = null;
private String _mobile = null;
private int _capacity = Integer.MIN_VALUE;
private int _status = Integer.MIN_VALUE;
private boolean _is_draft = false;
private boolean _isis_draftSet = false;
private int _notification = Integer.MIN_VALUE;
private Date _created = null;
private int _creator = Integer.MIN_VALUE;
private Date _updated = null;
private int _updator = Integer.MIN_VALUE;
private boolean _deleted = false;
private boolean _isdeletedSet = false;
private Date _deletion_time = null;


	public VenueModel() {
	}

// get/set
public int getId() {
		return _id;
	}
public void setId(int value) {
		_id = value;
	}
public String getName() {
		return _name;
	}
public void setName(String value) {
		_name = value;
	}
public String getCode() {
		return _code;
	}
public void setCode(String value) {
		_code = value;
	}
public String getDescription() {
		return _description;
	}
public void setDescription(String value) {
		_description = value;
	}
public int getIdCompany() {
		return _id_company;
	}
public void setIdCompany(int value) {
		_id_company = value;
	}
public String getAbbName() {
		return _abb_name;
	}
public void setAbbName(String value) {
		_abb_name = value;
	}
public String getShortName() {
		return _short_name;
	}
public void setShortName(String value) {
		_short_name = value;
	}
public String getForeignName() {
		return _foreign_name;
	}
public void setForeignName(String value) {
		_foreign_name = value;
	}
public String getAddress() {
		return _address;
	}
public void setAddress(String value) {
		_address = value;
	}
public String getMobile() {
		return _mobile;
	}
public void setMobile(String value) {
		_mobile = value;
	}
public int getCapacity() {
		return _capacity;
	}
public void setCapacity(int value) {
		_capacity = value;
	}
public int getStatus() {
		return _status;
	}
public void setStatus(int value) {
		_status = value;
	}
public boolean getIsDraft() {
		return _is_draft;
	}
public void setIsDraft(boolean value) {
		_is_draft = value;
		_isis_draftSet = true;
	}
public boolean getIsDraftSet() {
		return _isis_draftSet;
	}
public int getNotification() {
		return _notification;
	}
public void setNotification(int value) {
		_notification = value;
	}
public Date getCreated() {
		return _created;
	}
public void setCreated(Date value) {
		_created = value;
	}
public int getCreator() {
		return _creator;
	}
public void setCreator(int value) {
		_creator = value;
	}
public Date getUpdated() {
		return _updated;
	}
public void setUpdated(Date value) {
		_updated = value;
	}
public int getUpdator() {
		return _updator;
	}
public void setUpdator(int value) {
		_updator = value;
	}
public boolean getDeleted() {
		return _deleted;
	}
public void setDeleted(boolean value) {
		_deleted = value;
		_isdeletedSet = true;
	}
public boolean getDeletedSet() {
		return _isdeletedSet;
	}
public Date getDeletionTime() {
		return _deletion_time;
	}
public void setDeletionTime(Date value) {
		_deletion_time = value;
	}


	@Override
	public int[] getPrimaryKey() {
		int[] ids = new int[1];
		ids[0] = getId();
		return ids;
	}

	@Override
	public IModel readFromResultSet(ResultSet rs) throws SQLException {
		VenueModel model = null;

		if (rs.next()) {
			model = new VenueModel();

// read fields
{
				int value = rs.getInt("id");
				if (!rs.wasNull()) {
					model.setId(value);
				}
			}
{
				String value = rs.getString("name");
				if (!rs.wasNull()) {
					model.setName(value);
				}
			}
{
				String value = rs.getString("code");
				if (!rs.wasNull()) {
					model.setCode(value);
				}
			}
{
				String value = rs.getString("description");
				if (!rs.wasNull()) {
					model.setDescription(value);
				}
			}
{
				int value = rs.getInt("id_company");
				if (!rs.wasNull()) {
					model.setIdCompany(value);
				}
			}
{
				String value = rs.getString("abb_name");
				if (!rs.wasNull()) {
					model.setAbbName(value);
				}
			}
{
				String value = rs.getString("short_name");
				if (!rs.wasNull()) {
					model.setShortName(value);
				}
			}
{
				String value = rs.getString("foreign_name");
				if (!rs.wasNull()) {
					model.setForeignName(value);
				}
			}
{
				String value = rs.getString("address");
				if (!rs.wasNull()) {
					model.setAddress(value);
				}
			}
{
				String value = rs.getString("mobile");
				if (!rs.wasNull()) {
					model.setMobile(value);
				}
			}
{
				int value = rs.getInt("capacity");
				if (!rs.wasNull()) {
					model.setCapacity(value);
				}
			}
{
				int value = rs.getInt("status");
				if (!rs.wasNull()) {
					model.setStatus(value);
				}
			}
{
				boolean value = rs.getBoolean("is_draft");
				if (!rs.wasNull()) {
					model.setIsDraft(value);
				}
			}
{
				int value = rs.getInt("notification");
				if (!rs.wasNull()) {
					model.setNotification(value);
				}
			}
{
				Date value = rs.getDate("created");
				if (!rs.wasNull()) {
					model.setCreated(value);
				}
			}
{
				int value = rs.getInt("creator");
				if (!rs.wasNull()) {
					model.setCreator(value);
				}
			}
{
				Date value = rs.getDate("updated");
				if (!rs.wasNull()) {
					model.setUpdated(value);
				}
			}
{
				int value = rs.getInt("updator");
				if (!rs.wasNull()) {
					model.setUpdator(value);
				}
			}
{
				boolean value = rs.getBoolean("deleted");
				if (!rs.wasNull()) {
					model.setDeleted(value);
				}
			}
{
				Date value = rs.getDate("deletion_time");
				if (!rs.wasNull()) {
					model.setDeletionTime(value);
				}
			}
		
		}

		return model;
	}

	@Override
	public PreparedStatement genSelectStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "SELECT * FROM sp_venue_select(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        VenueModel obj = (VenueModel )query;
		
// set parameters
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genSelectListStatement(Connection dbConn,
			IModelExt query) throws SQLException {
		String sql = "SELECT * FROM sp_venue_selectList(:limit, :offset, :id,:name,:code,:description,:id_company,:abb_name,:short_name,:foreign_name,:address,:mobile,:capacity,:status,:is_draft,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		VenueModelExt obj = (VenueModelExt) query;

		if (obj.getLimit() != Integer.MIN_VALUE) {
			st.setObject("limit", obj.getLimit());
		}  else {
			st.setObject("limit", Integer.MAX_VALUE);
		}
		if (obj.getOffset() != Integer.MIN_VALUE) {
			st.setObject("offset", obj.getOffset());
		}  else {
			st.setObject("offset", 0);
		}

// set parameters
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
            st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
            st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
            st.setObject("id_company", null);
}
if (obj.getAbbName() != null) {
			st.setObject("abb_name", obj.getAbbName());
		} else {
            st.setObject("abb_name", null);
}
if (obj.getShortName() != null) {
			st.setObject("short_name", obj.getShortName());
		} else {
            st.setObject("short_name", null);
}
if (obj.getForeignName() != null) {
			st.setObject("foreign_name", obj.getForeignName());
		} else {
            st.setObject("foreign_name", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
            st.setObject("address", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
            st.setObject("mobile", null);
}
if (obj.getCapacity() != Integer.MIN_VALUE) {
			st.setObject("capacity", obj.getCapacity());
		} else {
            st.setObject("capacity", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
            st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
            st.setObject("notification", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genInsertStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_venue_insert(:name,:code,:description,:id_company,:abb_name,:short_name,:foreign_name,:address,:mobile,:capacity,:status,:is_draft,:notification,:creator)";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		VenueModel obj = (VenueModel) model;

		// set parameters here
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
			st.setObject("id_company", null);
}
if (obj.getAbbName() != null) {
			st.setObject("abb_name", obj.getAbbName());
		} else {
			st.setObject("abb_name", null);
}
if (obj.getShortName() != null) {
			st.setObject("short_name", obj.getShortName());
		} else {
			st.setObject("short_name", null);
}
if (obj.getForeignName() != null) {
			st.setObject("foreign_name", obj.getForeignName());
		} else {
			st.setObject("foreign_name", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
			st.setObject("address", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
			st.setObject("mobile", null);
}
if (obj.getCapacity() != Integer.MIN_VALUE) {
			st.setObject("capacity", obj.getCapacity());
		} else {
			st.setObject("capacity", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
			st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
			st.setObject("creator", null);
}
	

		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genUpdateStatement(Connection dbConn, IModel model)
			throws SQLException {
		String sql = "SELECT sp_company_update(:name,:code,:description,:id_company,:abb_name,:short_name,:foreign_name,:address,:mobile,:capacity,:status,:is_draft,:notification,:updator,:deleted,:deletion_time";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		VenueModel obj = (VenueModel) model;

		// set parameters here
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
			st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
			st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
			st.setObject("description", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
			st.setObject("id_company", null);
}
if (obj.getAbbName() != null) {
			st.setObject("abb_name", obj.getAbbName());
		} else {
			st.setObject("abb_name", null);
}
if (obj.getShortName() != null) {
			st.setObject("short_name", obj.getShortName());
		} else {
			st.setObject("short_name", null);
}
if (obj.getForeignName() != null) {
			st.setObject("foreign_name", obj.getForeignName());
		} else {
			st.setObject("foreign_name", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
			st.setObject("address", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
			st.setObject("mobile", null);
}
if (obj.getCapacity() != Integer.MIN_VALUE) {
			st.setObject("capacity", obj.getCapacity());
		} else {
			st.setObject("capacity", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
			st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
			st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
			st.setObject("notification", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
			st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
			st.setObject("deleted", null);
}
if (obj.getDeletionTime() != null) {
			st.setObject("deletion_time", obj.getDeletionTime());
		} else {
			st.setObject("deletion_time", null);
}

	
		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genDeleteStatement(Connection dbConn, IModel query)
			throws SQLException {
		String sql = "select sp_venue_delete(:id);";
		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

        VenueModel obj = (VenueModel) query;

		// set primary keys
st.setObject("id", obj.getId());


		return st.getPreparedStatement();
	}

	@Override
	public PreparedStatement genCountStatement(Connection dbConn,
			IModelExt input) throws SQLException {
		String sql = "SELECT sp_venue_count(:id,:name,:code,:description,:id_company,:abb_name,:short_name,:foreign_name,:address,:mobile,:capacity,:status,:is_draft,:notification,:createdFrom,:createdTo,:creator,:updatedFrom,:updatedTo,:updator,:deleted,:deletion_timeFrom,:deletion_timeTo)";

		NamedParameterPreparedStatement st = new NamedParameterPreparedStatement(
				dbConn, sql);

		VenueModelExt obj = (VenueModelExt) input;

		// set parameters here
if (obj.getId() != Integer.MIN_VALUE) {
			st.setObject("id", obj.getId());
		} else {
            st.setObject("id", null);
}
if (obj.getName() != null) {
			st.setObject("name", obj.getName());
		} else {
            st.setObject("name", null);
}
if (obj.getCode() != null) {
			st.setObject("code", obj.getCode());
		} else {
            st.setObject("code", null);
}
if (obj.getDescription() != null) {
			st.setObject("description", obj.getDescription());
		} else {
            st.setObject("description", null);
}
if (obj.getIdCompany() != Integer.MIN_VALUE) {
			st.setObject("id_company", obj.getIdCompany());
		} else {
            st.setObject("id_company", null);
}
if (obj.getAbbName() != null) {
			st.setObject("abb_name", obj.getAbbName());
		} else {
            st.setObject("abb_name", null);
}
if (obj.getShortName() != null) {
			st.setObject("short_name", obj.getShortName());
		} else {
            st.setObject("short_name", null);
}
if (obj.getForeignName() != null) {
			st.setObject("foreign_name", obj.getForeignName());
		} else {
            st.setObject("foreign_name", null);
}
if (obj.getAddress() != null) {
			st.setObject("address", obj.getAddress());
		} else {
            st.setObject("address", null);
}
if (obj.getMobile() != null) {
			st.setObject("mobile", obj.getMobile());
		} else {
            st.setObject("mobile", null);
}
if (obj.getCapacity() != Integer.MIN_VALUE) {
			st.setObject("capacity", obj.getCapacity());
		} else {
            st.setObject("capacity", null);
}
if (obj.getStatus() != Integer.MIN_VALUE) {
			st.setObject("status", obj.getStatus());
		} else {
            st.setObject("status", null);
}
		if (obj.getIsDraftSet()) {
			st.setObject("is_draft", obj.getIsDraft());
		} else {
            st.setObject("is_draft", null);
}
if (obj.getNotification() != Integer.MIN_VALUE) {
			st.setObject("notification", obj.getNotification());
		} else {
            st.setObject("notification", null);
}
if (obj.getCreatedFrom() != null) {
			st.setObject("createdFrom", obj.getCreatedFrom());
		} else {
			st.setObject("createdFrom", null);
		}
		if (obj.getCreatedTo() != null) {
			st.setObject("createdTo", obj.getCreatedTo());
		} else {
            st.setObject("createdTo", null);
}
if (obj.getCreator() != Integer.MIN_VALUE) {
			st.setObject("creator", obj.getCreator());
		} else {
            st.setObject("creator", null);
}
if (obj.getUpdatedFrom() != null) {
			st.setObject("updatedFrom", obj.getUpdatedFrom());
		} else {
			st.setObject("updatedFrom", null);
		}
		if (obj.getUpdatedTo() != null) {
			st.setObject("updatedTo", obj.getUpdatedTo());
		} else {
            st.setObject("updatedTo", null);
}
if (obj.getUpdator() != Integer.MIN_VALUE) {
			st.setObject("updator", obj.getUpdator());
		} else {
            st.setObject("updator", null);
}
		if (obj.getDeletedSet()) {
			st.setObject("deleted", obj.getDeleted());
		} else {
            st.setObject("deleted", null);
}
if (obj.getDeletionTimeFrom() != null) {
			st.setObject("deletion_timeFrom", obj.getDeletionTimeFrom());
		} else {
			st.setObject("deletion_timeFrom", null);
		}
		if (obj.getDeletionTimeTo() != null) {
			st.setObject("deletion_timeTo", obj.getDeletionTimeTo());
		} else {
            st.setObject("deletion_timeTo", null);
}

	
		return st.getPreparedStatement();
	}
}